<?php
/**
 * Created by PhpStorm.
 * User: 29620
 * Date: 2021/11/24
 * Time: 9:07
 */
namespace app\admin\model;

use think\Model;

class Brand extends Model
{
    protected $pk = 'brand_id';

    //获取器
    public function getRecommendedZhAttr($v,$d)  { return $d['recommended']?'是':'否'; }
    public function getIfShowZhAttr($v,$d)  { return $d['if_show']?'是':'否'; }
    public function getBrandLogoZhAttr($v,$d)  { return $d['brand_logo']?:'X.jpg'; }


    //搜索器
    public static function searchKeywordsAttr($q,$v,$d) { $q->where('brand_name','like',"%{$v}%"); }
    public function searchRecommendedAttr($q,$v,$d){$q->where('recommended','=',$v);}
    public function searchIfShowAttr($q,$v,$d){$q->where('if_show','in',$v);}
    public function searchBrandLogoAttr($q,$v,$d)
    {
        if ($v==1){
            $q->where('brand_logo','<>','');
        }else{
            $q->where(function ($q){
                $q->whereOr('brand_logo','=',null);
                $q->whereOr('brand_logo','=','');
            });

        }
    }
    public static function getBrand($where,$param)
    {
        $info = Brand::withSearch(array_keys($where),$where)->paginate(['list_rows' => 5,'query' => $param]);
        return $info;
    }
}